from jqgame.basegame import GameType
from quanjushang.models import QuanjushangGame
from quanjushang.ser import QuanjushangGamSer
from wuxianshang.models import WuxianshangExtendBoss, WuxianshangGame
from wuxianshang.serializers import (
    WuxianshangGameSerializer,
    WuxianshangExtendBossSerializer,
)
from yifanshang.models import YifanshangGame
from yifanshang.serializers import YifanshangGameSerializer

_game_type_name = {
    GameType.wuxianshang: "无限赏",
    GameType.wuxianshang_boss: "无限赏-boss赏",
    GameType.quanjushang: "全局赏",
    GameType.yifanshang: "一番赏",
}


def get_game_name(game_type):
    """
    获取游戏类型的中文名称
    Args:
        game_type: 游戏类型

    Returns: 中文名称

    """
    return _game_type_name[game_type]


def _mapper_wuxianshang_game(game_uuid):
    game = WuxianshangGame.objects.filter(uuid=game_uuid).first()
    if game is None:
        return None
    return WuxianshangGameSerializer(game).data


def _mapper_wuxianshang_boss_game(game_uuid):
    game = WuxianshangGame.objects.filter(uuid=game_uuid).first()
    if game is None:
        return None
    game_data = WuxianshangGameSerializer(game).data
    if game.extend_type_boss:
        boss = WuxianshangExtendBoss.objects.filter(game_uuid=game.uuid).first()
        if boss is not None:
            game_data["extend"] = {"boos": WuxianshangExtendBossSerializer(boss).data}
    return game_data


def _mapper_quanjushang_game(game_uuid):
    game = QuanjushangGame.objects.filter(uuid=game_uuid).first()
    if game is None:
        return None
    return QuanjushangGamSer(game).data


def _mapper_yifanshang_game(game_uuid):
    game = YifanshangGame.objects.filter(uuid=game_uuid).first()
    if game is None:
        return None
    return YifanshangGameSerializer(game).data


_game_type_mapper_game = {
    GameType.wuxianshang: _mapper_wuxianshang_game,
    GameType.wuxianshang_boss: _mapper_wuxianshang_boss_game,
    GameType.quanjushang: _mapper_quanjushang_game,
    GameType.yifanshang: _mapper_yifanshang_game,
}

_game_type_object_mapper = {
    GameType.wuxianshang: WuxianshangGame.objects,
    GameType.wuxianshang_boss: WuxianshangGame.objects,
    GameType.quanjushang: QuanjushangGame.objects,
    GameType.yifanshang: YifanshangGame.objects,
}


def get_game_type_objects(game_type):
    return _game_type_object_mapper.get(GameType(game_type))


_game_type_table_name_mapper = {
    GameType.wuxianshang: "WuxianshangGame",
    GameType.wuxianshang_boss: "WuxianshangGame",
    GameType.quanjushang: "QuanjushangGame",
    GameType.yifanshang: "YifanshangGame",
}


def get_game_type_table_name(game_type):
    return _game_type_table_name_mapper.get(GameType(game_type))


def get_game_data(game_uuid, game_type):
    """
    根据游戏uuid游戏类型和获取当前类型下的游戏数据
    Args:
        game_uuid: 游戏uuid
        game_type: 游戏类型

    Returns:

    """
    mapper = _game_type_mapper_game.get(GameType(game_type))
    if mapper is None:
        return None
    return mapper(game_uuid)
